const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
function wxRequest(url, data, success, method) {
  wx.showLoading({
    title: '加载中...',
  })
  wx.request({
    url: "https://api.letouhr.com/"+url,
    data: data,
    method: method,
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success:function(res){
      wx.hideLoading();
      if (res.data.code == 0){
        success(res)
      } else{
        wx.showToast({
          title: res.data.message,
          icon:'none'
        })
      }
      
    },
    fail:function(res){

    }
  })
}
function randomString(len) {
  　　len = len || 32;
  　　var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  　　var maxPos = $chars.length;
  　　var pwd = '';
  　　for (let i = 0; i < len; i++) {
  　　　　pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  　　}
  　　return pwd;
  }

module.exports = {
  formatTime: formatTime,
  wxRequest: wxRequest,
  random_str:randomString
}
